#include "dialogwin.h"
#include "ui_dialogwin.h"
#include <QMessageBox>
#include <QFileDialog>
#include <QColorDialog>
#include <QInputDialog>
#include <QFontDialog>
#include <mydialog.h>
#include <QDebug>
dialogwin::dialogwin(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::dialogwin)
{
    ui->setupUi(this);
}

dialogwin::~dialogwin()
{
    delete ui;
}

void dialogwin::on_pushButton_msg_clicked()
{
    int ret = QMessageBox::warning(this,"选择提示","请选择yes/no",QMessageBox::Yes,QMessageBox::No);
    if(ret == QMessageBox::Yes){
        ui->label_msg->setText("yes");
    }else {
        ui->label_msg->setText("no");
    }
}

void dialogwin::on_pushButton_path_clicked()
{
    //文件对话框-获取文件路径
    QString path = QFileDialog::getOpenFileName(this);
    ui->label_path->setText(path);
}

void dialogwin::on_pushButton_color_clicked()
{
    //颜色对话框--获取颜色对象--QColor
    QColor color =  QColorDialog::getColor();
    //字符串打包arg--sprintf
    QString style = QString("background-color:%1;color:%2").arg(color.name()).arg(color.name());
    ui->label_color->setStyleSheet(style);
}

void dialogwin::on_pushButton_input_clicked()
{
    //输入对话框-获取输入的内容
    bool ok;
    QString data = QInputDialog::getText(this, "输入提示","请输入密码",QLineEdit::Password,"123456",&ok);
    if(ok)
    {
        ui->label_input->setText(data);
    }
}

void dialogwin::on_pushButton_font_clicked()
{
    bool ok;
    QFont font = QFontDialog::getFont(&ok,this);
    if(ok)
    {
        ui->label_font->setFont(font);
    }
}

void dialogwin::on_pushButton_self_clicked()
{
    //创建一个对话框
    myDialog myDialog;
    int ret = myDialog.exec();
    if(ret == QDialog::Accepted)
    {
        qDebug()<<"Accepted";
    }
    if(ret == QDialog::Rejected)
    {
        qDebug()<<"Rejected";
    }
}
